package com.zlp.partice.io.niochat;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: zhulaiping
 * @time: 2022/8/18 17:13
 */
public class NIOServerDemo {

    public static void main(String[] args) throws IOException {
        ByteBuffer buffer = ByteBuffer.allocate(16);
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.bind(new InetSocketAddress(8080));
        List<SocketChannel> channels = new ArrayList<>();

        while (true){
            SocketChannel accept = serverSocketChannel.accept();
            channels.add(accept);
            for (SocketChannel channel : channels) {
                channel.read(buffer);
                buffer.flip();

            }
        }
    }
}
